﻿using System;
using System.Collections.Generic;
using System.Linq;
using ExpenseSystem.Common;
using ExpenseSystem.Fether;
using ExpenseSystem.Lor;
using ExpenseSystem.Model;

namespace ExpenseSystem.Fether
{
    public class RoleSiteFetcher:SystemFetcher<RoleSiteModel>,IDetailSystemFetcher<RoleSiteModel>
    {
        public IList<RoleSiteModel> ListBySiteId(long siteId, out string message,out int rows)
        {
            IList<RoleSiteModel> result = List( OrderBy.GetDefault(), Limit.GetDefault(), out message, out rows,Restrain.Eq("SiteId", siteId).And(Restrain.Eq("Avaliable", true)));
            return result;
        }
        public IList<RoleSiteModel> ListByRoleId(long roleId, out string message,out int rows)
        {
            IList<RoleSiteModel> result = List( OrderBy.GetDefault(), Limit.GetDefault(), out message, out rows, Restrain.Eq("RoleId", roleId).And(Restrain.Eq("Avaliable", true)));
            return result;
        }
        public RoleSiteModel GetByRoleIdAndSiteId(long roleId, long site, out string message)
        {
            int rows;
            IList<RoleSiteModel> result = List( OrderBy.GetDefault(), Limit.GetDefault(), out message, out rows, Restrain.Eq("SiteId", site).And(Restrain.Eq("RoleId", roleId)).And(Restrain.Eq("Avaliable", true)));
            if (result.Count > 0)
                return result.First();
            return null;
        }

        public IList<RoleSiteModel> ListByMainId(long mainId, out string message,out int rows)
        {
            return ListByRoleId(mainId,out message,out rows);
        }
    }
}
